#include<stdio.h>
#include<conio.h>
long tree[400000];
void printSpace(int n){
    while(n>0)printf(" ",n--);
}
void printDebug(long m){
    long i=2,j=0;
    do{
        printf("%4ld",tree[++j]);
        if(j==i-1){
            printf("\n");
            i*=2;
        }
    }while(j<=m);
    printf("\n");
    for(i=1;i<15;i++)printf("%4d",i);
}
long getlech(long m){
    long i=1;
    while(m>0){
        i<<=1;
        m>>=1;
    }
    return i;
}
long min(long a,long b){
    if(a>b)return b;
    else return a;
}
long max(long a,long b){
    if(a>b)return a;
    else return b;
}
void set(long index,long value){
    tree[index]=value;
    while(index>=1){
        tree[index>>1]=max(tree[index^1],tree[index]);
        index>>=1;
    }
}
long get(long index1,long index2){
    long maxRight=tree[index1],maxLeft=tree[index2];
    while(index1<index2-1){
        if((index1&1)==0)
            if(maxRight<tree[index1+1])maxRight=tree[index1+1];
        if((index2&1)==1)
            if(maxLeft<tree[index2-1])maxLeft=tree[index2-1];
        index1>>=1;
        index2>>=1;
    }
    return max(maxRight,maxLeft);
}
void process(){
    long i,m,n,lech,u,v,result;
    char c;
    FILE *fpinp=fopen("QUERY.INP","r");
    FILE *fpout=fopen("QUERY.OUT","w");
    
    fscanf(fpinp,"%ld%ld",&n,&m); 
    lech=getlech(n-1);
    for(i=0;i<m;i++){
        fscanf(fpinp,"%c%c%ld%ld",&c,&c,&u,&v);
        if(c=='Q'){
            result=get(min(u,v)-1+lech,lech+max(u,v)-1);
            fprintf(fpout,"%ld\n",result);
        //printf("\nQuery from %ld to %ld is %ld\n",u,v,result);
        }
        else{
            set(u-1+lech,v);
            //getch();
        }
    }
    
    fclose(fpinp);
    fclose(fpout);
}
int main(){
    process();
    return 0;
}
